﻿using System;
using System.Configuration;
using System.Web;
using System.Collections.Generic;

namespace CRMSystemV2.Web
{
    public class PageBase : System.Web.UI.Page
    {
        /// <summary>
        /// 分页信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public int pageIndex = 1;
        public int pageSize = 20;
        public int rowTotal = 0;
        public int pageTotal = 0;
        /// <summary>
        /// 搜索关键字
        /// </summary>
        protected static Dictionary<string, string> keyWords = new Dictionary<string, string>();
        /// <summary>
        /// 排序
        /// </summary>
        public string orderField = "";
        public string orderDirection = "";
        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            if (Session["username"] == null)
            {
                //session过期，弹出登录框
                //ajaxDone json = new ajaxDone()
                //{
                //    statusCode = 301,//dwz状态码（会话超时）
                //    callbackType = "closeCurrent"
                //};
                //json.ResponseWrite();

                //整页跳转
                HttpContext.Current.Response.Write("<script>top.location.href='Login.aspx'</script>");
            }
            else
            {
                //分页信息,该方法不能解决翻页定位问题
                pageIndex = Request["pageNum"] == null ? 1 : int.Parse(Request["pageNum"]);                
                pageSize = Request["numPerPage"] == null ? int.Parse(ConfigurationManager.AppSettings["pageSize"]) : int.Parse(Request["numPerPage"]);
                orderField = Request["orderField"] == null ? "" : Request["orderField"];
                orderDirection = Request["orderDirection"] == null ? "" : Request["orderDirection"];
            }
        }
        /// <summary>
        /// 获取搜索关键字的值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetValue(string key)
        {
            if (keyWords.Count == 0 || !keyWords.ContainsKey(key))
                return "";
            return keyWords[key];
        }
        /// <summary>
        /// 保存搜索关键字的值
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SetValue(string key, string value)
        {
            if (keyWords.Count == 0 || !keyWords.ContainsKey(key))
                keyWords.Add(key, value);
            else
                keyWords[key] = value;
        }
    }
}